package site.wlwsjsx.iot_backend.service.impl;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import site.wlwsjsx.iot_backend.dto.LabWorkstationStatsDTO;
import site.wlwsjsx.iot_backend.entity.LabInfo;
import site.wlwsjsx.iot_backend.mapper.LabInfoMapper;
import site.wlwsjsx.iot_backend.service.LabInfoService;

import java.util.List;

/**
 * 实验室信息服务实现类
 */
@Service
public class LabInfoServiceImpl implements LabInfoService {

    @Resource
    private LabInfoMapper labInfoMapper;

    @Override
    public LabInfo findById(Integer id) {
        return labInfoMapper.selectById(id);
    }

    @Override
    public List<LabInfo> findAll() {
        return labInfoMapper.selectAll();
    }

    @Override
    public int save(LabInfo labInfo) {
        return labInfoMapper.insert(labInfo);
    }

    @Override
    public int update(LabInfo labInfo) {
        return labInfoMapper.update(labInfo);
    }

    @Override
    public int deleteById(Integer id) {
        return labInfoMapper.deleteById(id);
    }

    @Override
    public List<LabInfo> findByPage(int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        return labInfoMapper.selectByPage(offset, pageSize);
    }

    @Override
    public Long countAll() {
        return labInfoMapper.countAll();
    }

    @Override
    public Integer findIdByLabCode(String labCode) {
        return labInfoMapper.selectIdByLabCode(labCode);
    }

    /**
     * 获取实验室工作站的统计数据
     * 该方法通过实验室ID查询并返回相应的工作站统计信息
     *
     * @param labId 实验室ID，用于标识特定的实验室
     * @return LabWorkstationStatsDTO 包含工作站统计数据的DTO对象
     */
    @Override
    public LabWorkstationStatsDTO getWorkstationStats(Integer labId) { // 方法声明，返回工作站统计信息
        return labInfoMapper.selectWorkstationStatsByLabId(labId); // 调用数据访问层方法获取统计数据
    }
}
